package com.adtech.farmProducts.activities.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.adtech.common.widgets.load.LoadFactory;
import com.adtech.common.widgets.load.core.LoadManager;
import com.adtech.common.widgets.load.view.AbsView;
import com.adtech.farmProducts.R;
import com.adtech.farmProducts.base.BaseActivity;
import com.adtech.farmProducts.base.BaseNfcActivity;
import com.adtech.farmProducts.model.SourceInfo;
import com.adtech.farmProducts.widget.LoadingView;

import butterknife.BindView;

/**
 * Time:2020/6/20
 * Created by xiaocz
 * Describe 详情
 */
public class InsertInfoActivity extends BaseNfcActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.layout_base)
    LinearLayout layout_base;
    @BindView(R.id.edit_gs_name)
    TextView edit_gs_name;
    @BindView(R.id.tv_address)
    TextView tv_address;
    @BindView(R.id.tv_time)
    TextView tv_time;

    @BindView(R.id.tv_code)
    TextView tv_code;
    @BindView(R.id.tv_name)
    TextView tv_name;
    @BindView(R.id.tv_unit)
    TextView tv_unit;
    @BindView(R.id.tv_weight)
    TextView tv_weight;
    @BindView(R.id.tv_create_name)
    TextView tv_create_name;

    private void showView(SourceInfo sourceInfo) {
        if (sourceInfo != null) {
            tv_code.setText(sourceInfo.getSourceCode());
            tv_name.setText(sourceInfo.getProductName());
            tv_unit.setText(sourceInfo.getPackUnit());
            tv_address.setText(sourceInfo.getAddress());
            edit_gs_name.setText(sourceInfo.getCompanyName());
            tv_weight.setText(sourceInfo.getWeight() + sourceInfo.getUnit());
            tv_time.setText(sourceInfo.getHandleTime());
            tv_create_name.setText(sourceInfo.getUserName());
        }
    }

    /**
     * DATA
     */
    private LoadManager mLoadManager;
    private SourceInfo sourceInfo;

    public static void show(Context context, SourceInfo sourceInfo) {
        Intent intent = new Intent(context, InsertInfoActivity.class);
        intent.putExtra("sourceInfo", sourceInfo);
        context.startActivity(intent);
    }

    @Override
    protected boolean initArgs(Bundle bundle) {
        if (bundle != null) {
            sourceInfo = bundle.getParcelable("sourceInfo");
        }
        return super.initArgs(bundle);
    }

    @Override
    protected int getLayoutSourceId() {
        return R.layout.activity_info;
    }


    @Override
    protected void initWidgets() {
        super.initWidgets();
        mLoadManager = LoadFactory.getInstance().register(layout_base, new AbsView.OnReloadListener() {
            @Override
            public void onReload(View view) {
                mLoadManager.showStateView(LoadingView.class);
            }
        });
        mLoadManager.showSuccessView();
    }


    @Override
    protected void initData() {
        super.initData();
        tvTitle.setText("详情");
        showView(sourceInfo);
    }
}
